import java.util.*;

public class Main {

    public static int V1Factorial(int n){
        int tmp = 0, ret = 0;
        for (int i = 1; i <= n; i++) {
            for(int j = 1;j<=i;j++) {
                tmp+=j;
            }
            ret+=tmp;
            tmp = 0;
        }

        return ret;
    }
    public static int V2Factorial(int n){
        int tmp = 0, ret = 0;
        for (int i = 1; i <= n; i++) {
            tmp = (i * (i + 1)) / 2;
            ret += tmp;
        }

        return ret;
    }
    public static int V3Factorial(int n){
        return n * (n + 1) * (n + 2) / 6;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想要求解的数字:");
        int n = sc.nextInt();
        long time1 = System.nanoTime();;
        long time2 = System.nanoTime();;

        System.out.println("解法一:");
        time1 = System.nanoTime();;
        System.out.println(V1Factorial(n));
        time2 = System.nanoTime();;
        System.out.println("运行时间(纳秒):"+(time2-time1));

        System.out.println("解法二:");
        time1 = System.nanoTime();;
        System.out.println(V2Factorial(n));
        time2 = System.nanoTime();;
        System.out.println("运行时间(纳秒):"+(time2-time1));

        System.out.println("解法三:");
        time1 = System.nanoTime();;
        System.out.println(V3Factorial(n));
        time2 = System.nanoTime();;
        System.out.println("运行时间(纳秒):"+(time2-time1));

        sc.close();
    }
}